import React from 'react';
import { Route, Switch } from 'react-router-dom';
import Login from './pages/login';
import Dashboard from './pages/dashboard';
import ChatRecord from './pages/chatrecord';
import MessageList from './pages/messagelist'
import {inject, observer} from "mobx-react";
import {message} from 'antd';
import styles from "./pages/chat/index.module.less";
import IF from './components/If';


@inject(({commonState})=>({commonState}))
@observer
class App extends React.Component {

	componentWillMount() {
		const remote = window.electron.remote;
		const isAllowLogin = remote.getGlobal('isAllowLogin');
		const platform = remote.getGlobal('platform');
		console.log('platform-isAllowLogin', `${platform}-${isAllowLogin}`);
		console.log('node:', remote.process.versions.node);
		console.log('electron:', remote.process.versions.electron);
		console.log('chrome:', remote.process.versions.chrome);

		if (isAllowLogin) {
			const store = remote.getGlobal('store');
			const currentWinId = remote.getCurrentWindow().id;
			const winName = store.get(String(currentWinId));
			if (winName === 'chatlistview') {
				window.location.hash = `/chatrecord`;
			} else if (winName === 'newMessageView') {
				window.location.hash = `/messagelist`;
			} else {
				window.location.hash = `/dashboard`;
			}
		} else {
			window.location.hash = `/login`;
		}

		//alert(this.props.commonState.initStatus)


	}

	render() {
		let initStatus = this.props.commonState.initStatus
		return (
			<div>
				<IF condition={initStatus == 'connecting'}>
					<div className={styles.statusInfo}>连接中...</div>
				</IF>

				<Switch>
					<Route path='/login' component={Login} />
					<Route path='/dashboard' component={Dashboard} />
					<Route path='/chatrecord' component={ChatRecord} />
					<Route path='/messagelist' component={MessageList} />
				</Switch>
			</div>
		);
	}
}

export default App;
